package com.mystudy.train.member.controller;

import com.mystudy.train.common.context.LoginMemberContext;
import com.mystudy.train.common.exception.BusinessExceptionEnum;
import com.mystudy.train.common.resp.CommonResp;
import com.mystudy.train.common.resp.PageResp;
import com.mystudy.train.member.req.PassengerQueryReq;
import com.mystudy.train.member.req.PassengerSaveReq;
import com.mystudy.train.member.resp.PassengerQueryResp;
import com.mystudy.train.member.service.PassengerService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author SaoE
 * @date 2025/1/7 22:02
 */
@RestController
@RequestMapping("/passenger")
public class PassengerController {

    @Autowired
    private PassengerService passengerService;

    @PostMapping("/save")
    public CommonResp register(@Valid @RequestBody PassengerSaveReq passengerSaveReq) {
        passengerService.save(passengerSaveReq);
        return new CommonResp<>(BusinessExceptionEnum.OPERATION_SUCCESS.getDesc(), null);
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<PassengerQueryResp>> queryList(@Valid PassengerQueryReq req){
        req.setMemberId(LoginMemberContext.getId());
        PageResp<PassengerQueryResp> passengerQueryRespPageResp = passengerService.queryList(req);
        return new CommonResp<>(BusinessExceptionEnum.OPERATION_SUCCESS.getDesc(), passengerQueryRespPageResp);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        passengerService.delete(id);
        return new CommonResp<>(BusinessExceptionEnum.OPERATION_SUCCESS.getDesc(), null);
    }

    @GetMapping("/query-mine")
    public CommonResp<List<PassengerQueryResp>> queryMine() {
        List<PassengerQueryResp> list = passengerService.queryMine();
        return new CommonResp<>(list);
    }

}
